{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Angle Between Hands of a Clock"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: angleClock"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #时钟指针的夹角"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个数&nbsp;<code>hour</code>&nbsp;和&nbsp;<code>minutes</code>&nbsp;。请你返回在时钟上，由给定时间的时针和分针组成的较小角的角度（60 单位制）。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<p><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/02/08/sample_1_1673.png\" style=\"height: 225px; width: 230px;\"></p>\n",
    "\n",
    "<pre><strong>输入：</strong>hour = 12, minutes = 30\n",
    "<strong>输出：</strong>165\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<p><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/02/08/sample_2_1673.png\" style=\"height: 225px; width: 230px;\"></p>\n",
    "\n",
    "<pre><strong>输入：</strong>hour = 3, minutes = 30\n",
    "<strong>输出；</strong>75\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<p><strong><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/02/08/sample_3_1673.png\" style=\"height: 231px; width: 230px;\"></strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>hour = 3, minutes = 15\n",
    "<strong>输出：</strong>7.5\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 4：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>hour = 4, minutes = 50\n",
    "<strong>输出：</strong>155\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 5：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>hour = 12, minutes = 0\n",
    "<strong>输出：</strong>0\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= hour &lt;= 12</code></li>\n",
    "\t<li><code>0 &lt;= minutes &lt;= 59</code></li>\n",
    "\t<li>与标准答案误差在&nbsp;<code>10^-5</code>&nbsp;以内的结果都被视为正确结果。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [angle-between-hands-of-a-clock](https://leetcode.cn/problems/angle-between-hands-of-a-clock/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [angle-between-hands-of-a-clock](https://leetcode.cn/problems/angle-between-hands-of-a-clock/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['12\\n30', '3\\n30', '3\\n15']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        h_angle = ((hour%12) * (360 / 12)) + ((360 / 12) / 60) * minutes\n",
    "        m_angle = (360 / 60) * minutes\n",
    "        angle1 = abs(m_angle - h_angle)\n",
    "        angle2 = 360 - angle1\n",
    "        return min((angle1, angle2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        a2 = minutes * 6\n",
    "        a1 = (hour % 12 + minutes / 60) * 30\n",
    "        return min(abs(a2 - a1), 360 - abs(a2 - a1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        \n",
    "        if hour!=12:\n",
    "            h_angle= (hour+ minutes/60 ) *30\n",
    "        else:\n",
    "            h_angle= (minutes/60 ) *30\n",
    "\n",
    "        m_angle= minutes*6\n",
    "        \n",
    "        angle=abs(h_angle-m_angle)\n",
    "\n",
    "        return min(angle,360-angle)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        per_hour_angle=30\n",
    "        per_min_angle=6\n",
    "        hours_angle=(hour%12+minutes/60)*per_hour_angle\n",
    "        mins_angle=minutes*per_min_angle\n",
    "        theta=abs(hours_angle-mins_angle)\n",
    "        return min(theta,360-theta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\r\n",
    "        \r\n",
    "        min_ptr = minutes/60*360\r\n",
    "        \r\n",
    "        if hour >= 12:\r\n",
    "            hour -= 12\r\n",
    "        hour_ptr = hour/12*360 + minutes/60 * 30\r\n",
    "        \r\n",
    "        result1 = abs(min_ptr - hour_ptr) \r\n",
    "        \r\n",
    "        result2 = abs(360 - result1)\r\n",
    "        \r\n",
    "        return min(result1, result2)\r\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        minute_hand_potion = minutes / 60\n",
    "        hour_hand_potion = (hour + minute_hand_potion) / 12\n",
    "\n",
    "        return min(abs(hour_hand_potion - minute_hand_potion) * 360, 360 - abs(hour_hand_potion - minute_hand_potion) * 360)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        h_angle = ((hour%12) * (360 / 12)) + ((360 / 12) / 60) * minutes\n",
    "        m_angle = (360 / 60) * minutes\n",
    "        angle1 = abs(m_angle - h_angle)\n",
    "        angle2 = 360 - angle1\n",
    "        return min((angle1, angle2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        one_min_angle=6\n",
    "        one_hour_angle=30\n",
    "        minutes_angle=one_min_angle*minutes\n",
    "        hour_angle=(hour%12 +minutes/60)*one_hour_angle\n",
    "        diff=abs(hour_angle-minutes_angle)\n",
    "        return min(diff,360-diff)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\r\n",
    "        \r\n",
    "        min_ptr = minutes/60*360\r\n",
    "        \r\n",
    "        if hour >= 12:\r\n",
    "            hour -= 12\r\n",
    "        hour_ptr = hour/12*360 + minutes/60 * 30\r\n",
    "        \r\n",
    "        result1 = abs(min_ptr - hour_ptr) \r\n",
    "        print(min_ptr, hour_ptr)\r\n",
    "        \r\n",
    "        result2 = abs(360 - result1)\r\n",
    "        \r\n",
    "        return min(result1, result2)\r\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        minute_hand_potion = minutes / 60\n",
    "        hour_hand_potion = hour / 12 + minute_hand_potion / 12\n",
    "\n",
    "        return min(abs(hour_hand_potion - minute_hand_potion) * 360, 360 - abs(hour_hand_potion - minute_hand_potion) * 360)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        deg_min = minutes/5 *30\n",
    "        deg_h = (hour % 12*30) + minutes/60 *30\n",
    "        return min(abs(deg_min - deg_h),360- abs(deg_min - deg_h)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        h = hour * 30 + minutes/60 * 30\n",
    "        m = minutes * 6\n",
    "        hm = h - m\n",
    "        ans = abs(hm)\n",
    "        if ans > 180:\n",
    "            return 360 - ans\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        one_min_angle = 6\n",
    "        one_hour_angle = 30\n",
    "        \n",
    "        minutes_angle = one_min_angle * minutes\n",
    "        hour_angle = (hour % 12 + minutes / 60) * one_hour_angle\n",
    "        \n",
    "        diff = abs(hour_angle - minutes_angle)\n",
    "        return min(diff, 360 - diff)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        mindeg = 360 * (minutes / 60)\n",
    "        hourdeg = 360 * (hour + (minutes / 60))/ 12\n",
    "        print(hourdeg, mindeg)\n",
    "        ret = max(hourdeg, mindeg) - min(hourdeg, mindeg)\n",
    "        return min(ret, 360 - ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        deg_min = minutes*6\n",
    "        deg_h = (hour % 12*30) + minutes/60 *30\n",
    "        return min(abs(deg_min - deg_h),360- abs(deg_min - deg_h)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        hour_position = ((hour * 5) + (5 * minutes)/60)%60\n",
    "        angle = abs(min((60 - abs(minutes - hour_position)),abs(minutes - hour_position)) * 6)\n",
    "        return angle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        h_angle = ((hour%12) * (360 / 12)) + ((360 / 12) / 60) * minutes\n",
    "        m_angle = (360 / 60) * minutes\n",
    "        angle1 = abs(m_angle - h_angle)\n",
    "        angle2 = 360 - angle1\n",
    "        return angle1 if angle1 < angle2 else angle2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        m = minutes * 6\n",
    "        if hour == 12:\n",
    "            hour = 0\n",
    "        h = hour * 30 + 30 / 60 * minutes\n",
    "        return min(abs(m - h), 360 - abs(m - h))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        one_min_angle = 6\n",
    "        one_hour_angle = 30\n",
    "        minutes_angle = one_min_angle * minutes\n",
    "        hour_angle = (hour % 12 + minutes / 60) * one_hour_angle\n",
    "        diff = abs(minutes_angle - hour_angle)\n",
    "        return min(diff, 360 - diff)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        angleh = hour * 30 + minutes / 2\n",
    "        anglem = minutes * 6\n",
    "        d = abs(angleh - anglem)\n",
    "        return min(d, 360-d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        angle = abs(360 * ((hour%12) / 12 - minutes / 60 * (1 - 1 / 12)))\n",
    "        return min(360-angle ,angle)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        h_unit=360/12\n",
    "        m_unit=360/60\n",
    "        if hour!=12:\n",
    "            h_angle= (hour+ minutes/60 ) *h_unit \n",
    "        else:\n",
    "            h_angle= (minutes/60 ) *h_unit \n",
    "\n",
    "        m_angle= minutes*m_unit \n",
    "        \n",
    "        angle=abs(h_angle-m_angle)\n",
    "\n",
    "        return min(angle,360-angle)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        hour_position = ((hour * 5) + (5 * minutes)/60)%60\n",
    "        angle = (min((60 - abs(minutes - hour_position)),abs(minutes - hour_position)) * 6)\n",
    "        return angle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        m_angle = minutes/60 * 360 \n",
    "        h_angle = (hour + minutes/60)%12 * 30\n",
    "        if(m_angle > h_angle):\n",
    "            return min(m_angle - h_angle, 360 - m_angle + h_angle)\n",
    "        else:\n",
    "            return min(h_angle - m_angle, 360 - h_angle + m_angle)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        unit_min = 360 // 60\n",
    "        unit_hour = 30\n",
    "        h = hour + minutes / 60\n",
    "        h_angle = h * unit_hour\n",
    "        m_angle = minutes * unit_min\n",
    "        cur_angle = abs(h_angle - m_angle)\n",
    "        if cur_angle > 180:\n",
    "            return 360 - cur_angle\n",
    "        else:\n",
    "            return cur_angle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        one_min_angle = 6\n",
    "        one_hour_angle = 30\n",
    "        \n",
    "        minutes_angle = one_min_angle * minutes\n",
    "        hour_angle = (hour % 12 + minutes / 60) * one_hour_angle\n",
    "        \n",
    "        diff = abs(hour_angle - minutes_angle)\n",
    "        return min(diff, 360 - diff)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        hour_position = ((hour * 5) + (5 * minutes)/60)%60\n",
    "        angle = (min((60 - abs(minutes - hour_position)),abs(minutes - hour_position)) * 6)\n",
    "        return angle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        deg = (minutes*6 - hour*30 - minutes*0.5 + 360) % 360\n",
    "        return min(deg,360-deg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        angle = abs(30 * hour- minutes * 11 / 2)\n",
    "        if angle > 180:\n",
    "            angle = 360 - angle\n",
    "        return angle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        deg_min = minutes/5 *30\n",
    "        deg_h = (hour % 12*30) + minutes/60 *30\n",
    "        return min(abs(deg_min - deg_h),360- abs(deg_min - deg_h)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "      hour_angle = (hour % 12) * 30 + (minutes / 60) * 30\n",
    "    # 每分钟分针移动的角度（360度/60分钟）\n",
    "      minute_angle = minutes * 6\n",
    "\n",
    "    # 计算两个角度之间的差值\n",
    "      angle = abs(hour_angle - minute_angle)\n",
    "    # 获取较小的角度\n",
    "      angle = min(360 - angle, angle)\n",
    "\n",
    "      return angle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        deg_min = minutes/5 *30\n",
    "        deg_h = (hour % 12*30) + minutes/60 *30\n",
    "        return min(abs(deg_min - deg_h),360- abs(deg_min - deg_h)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        timeh = ((hour % 12)*60 + minutes)/2\n",
    "        timem = 6 * minutes\n",
    "        return min(abs(timem - timeh),360 - abs(timem - timeh))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        angle = abs(30 * hour- minutes * 11 / 2)\n",
    "        return min(angle, 360-angle)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        if hour == 12:\n",
    "            hour = 0\n",
    "        a, b = (hour + minutes / 60) / 12 * 360, minutes / 60 * 360\n",
    "        if a < b:\n",
    "            a, b = b, a\n",
    "        return min(a - b, b - a + 360)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        m = minutes*6\n",
    "        h = (hour % 12 + minutes / 60) * 30\n",
    "        diff = abs(h - m)\n",
    "        return min(360 - diff, diff)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        m = minutes * 6\n",
    "        h = ((0 if hour == 12 else hour)* 60 + minutes) / 2\n",
    "\n",
    "\n",
    "        diff = abs(m - h)\n",
    "        return min(diff, 360 - diff)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        minute_angle = minutes * 6\n",
    "        hour_angle = 30 * (hour + minutes / 60)\n",
    "        interval = abs(minute_angle - hour_angle)\n",
    "        return min(interval, 360-interval)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        x = hour%12*30+minutes/2\n",
    "        y = minutes%60*6\n",
    "        print(x, y)\n",
    "        z = max(x, y) - min(x, y)\n",
    "        return z if z < 180 else 360-z\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        h = hour * 30 + minutes/60 * 30\n",
    "        m = minutes * 6\n",
    "        hm = h - m\n",
    "        hm1 = m - h\n",
    "        if h > m:\n",
    "            if hm > 180:\n",
    "                return 360 - hm\n",
    "            return h - m\n",
    "        else:\n",
    "            if hm1 > 180:\n",
    "                return 360 - hm1\n",
    "            return hm1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        one_min_angle = 6\n",
    "        one_hour_angle = 30\n",
    "        \n",
    "        minutes_angle = one_min_angle * minutes\n",
    "        hour_angle = (hour % 12 + minutes / 60) * one_hour_angle\n",
    "        \n",
    "        diff = abs(hour_angle - minutes_angle)\n",
    "        return min(diff, 360 - diff)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        m_angle = 360 * minutes/60\n",
    "        h_angle = 360 * (hour + minutes/60)/12\n",
    "        diff = abs(m_angle - h_angle)\n",
    "        return min(diff, 360 -diff)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        h_unit=360/12\n",
    "        m_unit=360/60\n",
    "        if hour!=12:\n",
    "            h_angle= (hour+ minutes/60 ) *h_unit \n",
    "        else:\n",
    "            h_angle= (minutes/60 ) *h_unit \n",
    "\n",
    "        m_angle= minutes*m_unit \n",
    "        \n",
    "        angle=abs(h_angle-m_angle)\n",
    "\n",
    "        return angle if angle<180 else 360-angle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        hour_ = {i: j for i , j in zip(range(0, 12) ,range(0, 360, 30))}\n",
    "        hour_[12] = 0\n",
    "        min = {i:j for i , j in zip(range(0,60),range(0,360,6))}\n",
    "        min_card = min[minutes]\n",
    "        hour_card = hour_[hour] + 30 * (minutes/60)\n",
    "        res = abs(min_card - hour_card)\n",
    "        if res <=180:\n",
    "            return res\n",
    "        else:\n",
    "\n",
    "            return 360-res \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        h_angle = ((hour%12) * (360 / 12)) + ((360 / 12) / 60) * minutes\n",
    "        m_angle = (360 / 60) * minutes\n",
    "        angle1 = m_angle - h_angle\n",
    "        angle1 = angle1 if angle1 >= 0 else -angle1\n",
    "        angle2 = 360 - angle1\n",
    "        angle = angle1 if angle1 < angle2 else angle2\n",
    "        return angle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        hour = hour % 12 + minutes / 60\n",
    "        minutes = minutes / 60 * 12\n",
    "\n",
    "        diff = abs(hour - minutes)/12 * 360\n",
    "\n",
    "        return min(diff, 360-diff)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        a, b = (hour % 12 * 60 + minutes) / 720, minutes / 60\n",
    "        return min(abs(a - b), 1 - abs(a - b)) * 360"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        one_min_angle = 6\n",
    "        one_hour_angle = 30\n",
    "        \n",
    "        minutes_angle = one_min_angle * minutes\n",
    "        hour_angle = (hour % 12 + minutes / 60) * one_hour_angle\n",
    "        \n",
    "        diff = abs(hour_angle - minutes_angle)\n",
    "        return min(diff, 360 - diff)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        hour = (hour + minutes / 60) % 12\n",
    "        minutes = minutes / 60 * 12\n",
    "\n",
    "        if hour - minutes == 0:\n",
    "            return 0\n",
    "        \n",
    "        if hour > 6:\n",
    "            if minutes > (hour+6)%12:\n",
    "                res = abs(hour - minutes)\n",
    "            else:\n",
    "                res = 12 - hour + minutes  \n",
    "        else:\n",
    "            if minutes > hour+6:\n",
    "                res = 12 - minutes + hour \n",
    "            else:\n",
    "                res = abs(hour - minutes)\n",
    "\n",
    "        \n",
    "        if res < 0:\n",
    "            res = 12 + res\n",
    "        res = res / 12 * 360\n",
    "        return res\n",
    "        if res > 180:\n",
    "            res = 360 - 180\n",
    "\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        a = minutes / 5\n",
    "        b = hour + minutes / 60\n",
    "        return abs(b - a) * 30 if abs(b - a) < 6 else 360-abs(b - a) * 30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minute: int) -> float:\n",
    "        if hour==12:\n",
    "            hour=0\n",
    "        hours=(hour+minute/60)*(360/12)\n",
    "        minutes=(minute/60)*(360)\n",
    "        print(hours,minutes)\n",
    "        dg=max(minutes,hours)-min(minutes,hours)\n",
    "        return dg if dg<=180 else 360-dg\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        angle1 = abs((360 / 60) * minutes - \n",
    "        (((hour%12) * (360 / 12)) + ((360 / 12) / 60) * minutes))\n",
    "        angle2 = 360 - angle1\n",
    "        return min((angle1, angle2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        h_angle = ((hour%12) * (360 / 12)) + ((360 / 12) / 60) * minutes\n",
    "        m_angle = (360 / 60) * minutes\n",
    "        angle1 = m_angle - h_angle\n",
    "        angle1 = angle1 if angle1 >= 0 else -angle1\n",
    "        angle2 = 360 - angle1\n",
    "        return angle1 if angle1 < angle2 else angle2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        hour%=12\n",
    "        minD=(minutes/60)*360\n",
    "        hD=hour*30+minutes/2\n",
    "        res=abs(hD-minD)\n",
    "        return min(res,360-res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        degreeMinute, degreeHour = 6,30\n",
    "        diff = abs(minutes*degreeMinute - (hour%12+minutes/60)*degreeHour)\n",
    "        return min(diff, 360-diff)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        if hour==12:\n",
    "            hour=0\n",
    "        angleminutes=minutes*6\n",
    "        anglehour=hour*30+minutes/2\n",
    "        sum=abs(angleminutes-anglehour)\n",
    "        if sum>=180:\n",
    "            sum=360-sum\n",
    "        return sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        hour = (hour % 12) *30 + minutes / 2\n",
    "        minutes *= 6\n",
    "        return min(abs(hour - minutes), 360 - abs(hour - minutes))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "\n",
    "\n",
    "        h = hour*30+minutes/60*30\n",
    "        m = minutes/60*360\n",
    "\n",
    "        x = abs(h-m)\n",
    "        return min(x, 360-x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minutes: int) -> float:\n",
    "        H_INTERVAL = 360 // 12\n",
    "        M_INTERVAL = 360 // 60\n",
    "\n",
    "        minuteOffset = minutes * M_INTERVAL\n",
    "        hourOffset = (hour + minutes/60) * H_INTERVAL\n",
    "\n",
    "        angle = abs(hourOffset - minuteOffset)\n",
    "        angle = 360 - angle if angle > 180 else angle\n",
    "\n",
    "        return angle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def angleClock(self, hour: int, minute: int) -> float:\n",
    "        if hour==12:\n",
    "            hour=0\n",
    "        hours=(hour+minute/60)*(360/12)\n",
    "        minutes=(minute/60)*(360)\n",
    "        # print(hours,minutes)\n",
    "        dg=max(minutes,hours)-min(minutes,hours)\n",
    "        return dg if dg<=180 else 360-dg\n",
    "\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
